package com.easybuilder.common.config.upload;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class UploadFilePathConfig extends WebMvcConfigurerAdapter {

    @Value("${file.staticAccessPath:/file/**}")
    private String staticAccessPath;
    @Value("${file.uploadFolder:C://uploadFiles/}")
    private String uploadFolder;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry.addResourceHandler(staticAccessPath).addResourceLocations("file:" + uploadFolder);

        //一定要添加以下方法，否则打成jar包后运行，访问不到
        super.addResourceHandlers(registry);
    }
}
